package com.atguigu.lease.app.controller;

import com.atguigu.lease.app.service.LeaseAgreementService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.LeaseAgreement;
import com.atguigu.lease.model.vo.app.AgreementDetailVo;
import com.atguigu.lease.model.vo.app.AgreementItemVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name="租约模块")
@RestController
@RequestMapping("/app/agreement")
public class AggrementController {
    @Autowired
    LeaseAgreementService leaseAgreementService;
    @Operation(summary = "1、查询当前用户的租约列表")
    @GetMapping("/listItem")
    public Result<List<AgreementItemVo>> listItem(){
        return Result.ok(leaseAgreementService.listItem());
    }

    @Operation(summary = "2,根据id查询租约详情")
    @GetMapping("/getDetailById")
    public Result<AgreementDetailVo> getDetailById(@RequestParam Long id) {
        return Result.ok(leaseAgreementService.getDetailById(id));
    }

    @Operation(summary = "3、新增或更新租约")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody LeaseAgreement leaseAgreement){
        leaseAgreementService.saveOrUpdateLeaseAgreement(leaseAgreement);
        return Result.ok();
    }
}